﻿using System;

namespace Development.Tools
{
    public  class Global
    {
        public static Random Rand = null;

        /// <summary>
        /// ms
        /// </summary>
        /// <returns></returns>
        public static long CurrTime()
        {
            long time = (long)(DateTime.Now.Ticks *  0.0001);
            return time;
        }

        public static float TickToM(long tick)
        {
            return tick * 0.0000001f;
        }

        public static string GetTimeString()
        {
            DateTime time = DateTime.Now;
            return string.Format("{0}_{1}_{2}_{3}_{4}_{5}",time.Year,time.Month,time.Day,time.Hour,time.Minute,time.Second);
        }
        /// <summary>
        /// 随机得float值，左闭右闭
        /// </summary>
        /// <param name="minValue">最大值</param>
        /// <param name="maxValue">最小值</param>
        /// <param name="floatCount">保留几位小数</param>
        /// <returns></returns>
        public static float GetFloatRand(float minValue, float maxValue,int floatCount = 1)
        {
            int chengshu = (int)System.Math.Pow(10, floatCount);
            int a = (int)(minValue * chengshu);
            int b = (int)(maxValue * chengshu);
            int c = Rand.Next(a, b + 1);
            return (float)c / (float)chengshu;
        }


        public static object CreateObject(string typeName)
        {
            object obj = null;
            try
            {
                Type objType = Type.GetType(typeName, true);
                obj = Activator.CreateInstance(objType);
            }
            catch (Exception ex)
            {
                Log.WriteLog(ELogLevel.LOG_ERROR, ex.Message);
            }
            return obj;
        }

        public static object CreateObject(Type type)
        {
            object obj = null;
            try
            {
                obj = Activator.CreateInstance(type);
            }
            catch (Exception ex)
            {
                Log.WriteLog(ELogLevel.LOG_ERROR, ex.Message);
            }
            return obj;
        }




    }


}
